Skip to content

Introduced Nope::VersionNotFound error #1043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 12, 2020
Merged

Conversation

robinhundt
Copy link
Contributor

Trying to reproduce the issue #55 revealed another bug: the order in which the different handlers were called in CratesfyiHandler::handle resulted in the more specific errors from the router_handler being dropped, due to them being 404 and the last handler being the static_handler which would just return a ResourceNotFound error.
It should be noted that the different execution order might affect the performance in production.

@jyn514 jyn514 added A-backend Area: Webserver backend S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed labels Sep 10, 2020
Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of little nit-picky comments, but the approach looks right. Thanks for working on this!

src/web/mod.rs Outdated
corrected_name,
version: MatchSemver::Exact((version.to_owned(), *id)),
});
}

// Now try to match with semver
let req_sem_ver = VersionReq::parse(&req_version).ok()?;
let req_sem_ver = VersionReq::parse(&req_version).map_err(|_| Nope::CrateNotFound)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be VersionNotFound?

Suggested change
let req_sem_ver = VersionReq::parse(&req_version).map_err(|_| Nope::CrateNotFound)?;
let req_sem_ver = VersionReq::parse(&req_version).map_err(|_| Nope::VersionNotFound)?;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a test for this case by requesting /:crate/some_version/, then make sure that it fails before and succeeds after this change.

@jyn514
Copy link
Member

jyn514 commented Sep 10, 2020

Can you also add some tests for the new behavior? There's examples around https://github.com/rust-lang/docs.rs/blob/master/src/web/rustdoc.rs#L821 - I don't think anything tests the error text currently, but it shouldn't be too hard to get it from the response: https://docs.rs/reqwest/0.10.8/reqwest/struct.Response.html#method.text

@jyn514 jyn514 added S-waiting-on-author Status: This PR is incomplete or needs to address review comments and removed S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed labels Sep 10, 2020
robinhundt added a commit to robinhundt/docs.rs that referenced this pull request Sep 11, 2020
robinhundt added a commit to robinhundt/docs.rs that referenced this pull request Sep 11, 2020
Trying to reproduce the issue rust-lang#55 revealed another bug: the order in which the different handlers were called in CratesfyiHandler::handle resulted in the more specific errors from the router_handler being dropped, due to them being 404 and the last handler being the static_handler which would just return a ResourceNotFound error.
It should be noted that the different execution order might affect the performance in production.
@jyn514
Copy link
Member

jyn514 commented Sep 11, 2020

Looks like you need to update the text for one of the tests:

[2020-09-11T18:37:05Z INFO  docs_rs::web] Running docs.rs web server on http://127.0.0.1:39637
thread 'web::error::tests::check_404_page_content' panicked at 'assertion failed: `(left == right)`
  left: `"The requested crate does not exist"`,
 right: `"The requested resource does not exist"`', src/web/error.rs:125:13

@robinhundt
Copy link
Contributor Author

Yea, I've already updated it. I was just confused for a moment because the failing test wasn't present in my branch so I had to fetch the origin and rebase.
I'll probably write the tests sometime this weekend 😊

@jyn514
Copy link
Member

jyn514 commented Sep 11, 2020

Sounds great! Thanks so much for working on this :)

@robinhundt robinhundt requested a review from jyn514 September 12, 2020 11:22
@jyn514 jyn514 added S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed and removed S-waiting-on-author Status: This PR is incomplete or needs to address review comments labels Sep 12, 2020
Copy link
Member

@jyn514 jyn514 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

Comment on lines +141 to +142
// routes_handler which is currently run last. This means that `get("resource.exe")` will
// fail with a `no so such crate` instead of 'no such resource'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, good catch. This seems like an ok bug to have though - if you're trying to download .exes docs.rs doesn't want to help you even as much to have the right error.

.next()
.unwrap()
.text_contents(),
"The requested version does not exist",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually it would be nice to instead say 'all versions of this crate are yanked', which makes more sense since this didn't request a specific version. But that can be a follow-up PR.

@jyn514 jyn514 merged commit c444b63 into rust-lang:master Sep 12, 2020
jyn514 pushed a commit that referenced this pull request Sep 12, 2020
Tests are still TODO
@robinhundt
Copy link
Contributor Author

Thanks for the help and quick, detailed reviews 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-backend Area: Webserver backend S-waiting-on-review Status: This pull request has been implemented and needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants